<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
function goodstree($data, $id=0, $level=0)
{
    /**
     * @param $rec 保存得到的数据. 变量一直在执行,不保存数据.所以加static
     */
    static $rec = array();
    foreach ($data as $val){
        if ($val['pid'] == $id) {
            // $val['level'] = $level;
            // var_dump($val);
            $rec[] = $val;
            // var_dump($rec);
            goodstree($data, $val['id'], $level + 1);
        }
    }
    return $rec;
}